window.onload=function () {
    var app = new Vue({
        el: "#app",
        data: {
            pagination: {
                total: 0, //总记录数
                pageSize: 10, //每页的记录数
                pageNum: 1, //当前页码
            },
            answerarr:[],//查询所以审核完成问答
            answers:{
                qid:"",//问题回答id
                uid:"",//发布用户
                name:"",//发布用户
                q_title:"",//标题
                state:"",//状态
                q_content:"",//内容
                tid:""//分配的牙齿类型
            },
            toucharray:[],//所以类型
            state:"",
            options:[//状态
                {
                value:'0',
                label: '已删除'
                },
                {
                    value:'1',
                    label: '上架'
                },
                {
                    value:'2',
                    label: '下架'
                }
            ],
            lookanswers:false,//查看详情弹出框
            updateanswerboxs:false//修改弹出框

        },
        methods: {
            inisarticleno(){
                //初始化数据
                methodaxios.get(null,"/question/questionlist?currentPage="+this.pagination.pageNum+"&pageSize="+this.pagination.pageSize+"&state="+this.state,rep=>{
                    window.console.log("================================");
                    window.console.log(rep.data.data);
                    this.answerarr=rep.data.data;
                    this.pagination.total=rep.data.count;
                });
            },
            inittouch(){//初始化牙齿类型
                methodaxios.get(null,"/touch/listanswer",rep=>{
                    window.console.log(rep)
                    this.toucharray=rep.data
                });
            },//当前页发送改变
            findBlogPageList(page) {
                //页数改变
                this.pagination.pageNum = page;
                this.inisarticleno();
            }, //每页大小发送改变
            sizeChange(size) {
                this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.inisarticleno();
            },//点击搜索
            searchswers(){
                this.pagination.pageNum = 1;
                this.inisarticleno();
            },//重置
            resetanswers(){
                this.state=""
                this.pagination.pageNum = 1;
                this.inisarticleno();
            },
            lookanswer(row){//查看当前问答
                var E = window.wangEditor
                var editor = new E('#editor')
                editor.create()
                this.lookanswers=true
                this.answers.q_title=row.q_title;
                this.answers.name=row.name;
                this.answers.tid=row.tid;
                editor.$textElem.attr('contenteditable', false)
                editor.txt.html('<p>' +row.q_content+'</p>' );
            },
            updateanswers(row){//点击修改
                this.answers.q_title=row.q_title;
                this.answers.qid=row.qid;
                this.answers.state=row.state;
                this.answers.name=row.name;
                this.answers.tid=row.tid;
                window.console.log("审核问答")
                window.console.log(row)
                window.console.log(this.answers)
                this.updateanswerboxs=true
                var E = window.wangEditor
                var editor = new E('#confirmupdateaanswers')
                editor.create()
                editor.$textElem.attr('contenteditable', false)
                editor.txt.html('<p>' +row.q_content+'</p>' );
            },
            confirmupdateaanswers(){//确定修改
                if(isBlank(this.answers.state)){
                    layer.msg("请指定状态");
                    return false;
                }
                // public int adminUpdateQa(@RequestParam int qid,@RequestParam int state,@RequestParam int tid);
                methodaxios.post("/question/updatelist",{
                    qid:this.answers.qid,
                    state:this.answers.state,
                    tid:this.answers.tid
                },rep=>{
                    if(rep.data.code==="200"){
                        this.answers.tid=""
                        this.answers.state=""
                        this.answers.qid=""
                        layer.msg("修改成功");
                        this.updateanswerboxs=false
                        this.inisarticleno();
                    }
                });
            }
        },mounted(){
            this.inisarticleno();
            this.inittouch();
        },
        filters:{
            mytime(value){
                var dateee = new Date( value).toJSON();
                return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
            },
            mystate(value){
                if(value=="0"){
                    return "删除"
                }else if(value=="1"){
                    return "上架"
                }else if(value=="2"){
                    return "下架"
                }
            }
        }

    })
}
